package com.example.cqh_votesys.sevice.impl;

import com.example.cqh_votesys.constant.MessageConstant;
import com.example.cqh_votesys.exception.RegisterException;
import com.example.cqh_votesys.mapper.RegisterMapper;
import com.example.cqh_votesys.pojo.DTO.RegisterDTO;
import com.example.cqh_votesys.sevice.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * @Author: pollux
 * @CreateTime: 2024-06-30
 * @Description: 注册业务类
 * @Version: 1.0
 */

@Service
public class RegisterServiceImpl implements RegisterService {

    @Autowired
    private RegisterMapper registerMapper;
    /**
     * @param registerDTO 注册DTO类
     * @description: 注册接口
     * @return:
     * @author: pollux
     * @date: 2024/6/30 13:04
     */
    @Override
    public void register(RegisterDTO registerDTO) {
        //比较两次密码是否一致
        if (!registerDTO.getPassword().equals(registerDTO.getConfirmPassword())){
             //抛出两个密码不一致的异常
             throw new RegisterException(MessageConstant.PASSWORD_NO_COMFIRM);
        }else {
             //进来这里将密码加密，直接添加进数据库
            registerDTO.setPassword(DigestUtils.md5DigestAsHex(registerDTO.getPassword().getBytes()));
            registerMapper.add(registerDTO);
        }


    }
}






